import {
	buildPageUrl,
	formatDate
} from '../common/util.js'

export default {
	data() {
		const pages = getCurrentPages()
		const currentPage = pages[pages.length - 1]
		const currentPageUrl = buildPageUrl(currentPage.route, currentPage.options)
		return {
			currentPage,
			currentPageUrl
		}
	},
	onLoad(options) {
		console.log('page onLoad', this.currentPageUrl);
	},
	methods: {
		onCopy(text) {
			uni.setClipboardData({
				data: text + ''
			}).then(([err, res]) => {
				console.log('uni.setClipboardData', err, res);
				if (!err) {
					uni.showToast({
						title: '复制成功',
						icon: 'none',
					});
				}
			});
		}
	},
	computed: {
		timeFormat() {
			return (timestamp) => {
				if (!timestamp) {
					return ''
				}
				return formatDate(timestamp, 'yyyy-MM-dd hh:mm:ss')
			}
		},
	},
}
